// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vuex from 'vuex'
import VueRouter from 'vue-router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import StoreConfig from './store/store'
import Util from './libs/util'
import RouterConfig from './router/config'
import Axios from './libs/axios'
import App from './App'

Vue.use(Vuex)
Vue.use(VueRouter)
Vue.use(ElementUI);

// 路由配置
const router = new VueRouter({
	// mode: 'history',
	// history: true,
	saveScrollPosition: true,
	transitionOnLoad: true,
	routes: RouterConfig
})

router.beforeEach((to, from, next) => {
	next()
});

router.afterEach((to, from) => {
	// 设置当前页面标题
	if (to.meta && to.meta.title) {
		Util.title(to.meta.title)
	}
});

// vuex
const store = new Vuex.Store(StoreConfig)

Vue.config.productionTip = false

// 注入对象
Axios.init(router, store)

const VM = new Vue({el: '#app', router, store: store, template: '<App/>', components: {
		App
	}})

export default VM
